<?php
class Category_model extends DNN_model
{
	protected $_table = 'category';
	
	private $_name = 'name_en';
	function __construct() {
		parent::__construct();
		$_name = 'name_'.$this->_language;
	}
	
	function get_paged_list($limit = 10, $offset = 0) {
		$this->db->select('id, '.$this->_name.' as name, type, parent_id');
		$this->db->from($this->_table);
		$this->db->order_by('name', 'asc');
		$this->db->limit($limit, $offset);
		return $this->db->get();
	}
	
	function get_by_id($id) {
		$this->db->select('id, '.$this->_name.' as name, type, parent_id');
		$this->db->from($this->_table);
		$this->db->where('id', $id);
		return $this->db->get();
	}
	
	function get_list_by_type($type) {
		$this->db->select('id, '.$this->_name.' as name, parent_id');
		$this->db->from($this->_table);
		$this->db->where('type', $type);
		if($type == 1) {
			$this->db->where('parent_id > 0');
		}
		$this->db->order_by('name', 'asc');
		return $this->db->get();
	}
	function get_list_parent($parent_id = 0) {
		$this->db->select('id, '.$this->_name.' as name, parent_id');
		$this->db->from($this->_table);
		$this->db->where('type', 1);
		$this->db->where('parent_id', $parent_id);
		$this->db->order_by('name', 'asc');
		return $this->db->get();
	}
}